<?php

//require_once  __DIR__ . '/includes/authenticate.php';

if (isset($_POST['season']) && isset($_POST['selectedgame'])) {
	
foreach ($_POST as $key => $value) {
	if ($value == '') {
      $value = ":null";
      $$key = $value;
     } else {
    	$$key = $value;
     }
  }

$sql = "UPDATE games 
SET score_exc_tot = $exctot, 
score_opp_tot = $opptot, 
score_exc_q1 = $excq1, 
score_exc_q2 = $excq2, 
score_exc_q3 = $excq3, 
score_exc_q4 = $excq4, 
score_opp_q1 = $oppq1, 
score_opp_q2 = $oppq2, 
score_opp_q3 = $oppq3, 
score_opp_q4 = $oppq4
WHERE gamenumber = '$selectedgame' 
AND season = '$season'";


try{
    $dbpdo = new PDO('mysql:host=localhost;dbname=basketbal','cas','cas');
    $dbpdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    $stmt = $dbpdo->prepare($sql);
	$stmt->bindValue(":null", null, PDO::PARAM_INT);
	if (!$stmt->execute()) {
    echo "Execute failed: (" . $stmt->errno . ") " . $stmt->error;
	} 
	echo "<center> Game results successfully updated </center>";
} catch (PDOException $e) {
    
    $error = $e->getMessage();
}

}

?>